<template>
  <div id="dialogDetailData">
    <div class="form-box">
      <el-dialog
        title="消息详情"
        :visible.sync="dialogData.isShow"
        width="510px"
      >
        <el-form
          :model="noticeDetail"
          label-width="90px"
          label-position="right"
        >
          <el-form-item label="触达时间">
            <el-input v-model="noticeDetail.touchTime" disabled></el-input>
          </el-form-item>
          <el-form-item label="触达通道">
            <el-select
              v-model="noticeDetail.touchType"
              style="width: 100%"
              disabled
              placeholder="请选择"
            >
              <el-option
                v-for="item in touchTypeList"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="
              noticeDetail.touchType === 'PUSH' ||
                noticeDetail.touchType === 'NOTICE'
            "
            :label="
              noticeDetail.touchType === 'NOTICE' ? '站内信标题' : '推送标题'
            "
          >
            <el-input v-model="noticeDetail.title" disabled></el-input>
          </el-form-item>
          <el-form-item
            v-if="noticeDetail.touchType !== 'BOMB_SCREEN'"
            :label="
              noticeDetail.touchType === 'NOTICE' ? '站内信内容' : '推送内容'
            "
          >
            <el-input
              v-model="noticeDetail.content"
              disabled
              type="textarea"
              :rows="4"
              resize="none"
            ></el-input>
          </el-form-item>
          <template v-if="noticeDetail.touchType === 'BOMB_SCREEN'">
            <el-form-item label="显示终端" prop="displayTerminals">
              <el-radio-group disabled v-model="noticeDetail.displayTerminals">
                <el-radio
                  v-for="item in terminalTypeList"
                  :key="item.dictValue"
                  :label="item.dictValue"
                >
                  {{ item.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="弹屏图片">
              <img
                v-if="noticeDetail.img"
                class="bomb-img"
                :src="noticeDetail.img"
                alt="弹屏图片"
              />
            </el-form-item>
          </template>
          <el-form-item
            v-if="noticeDetail.displayTerminals === 'APP'"
            prop="radioType"
          >
            <el-radio
              disabled
              v-for="item in radioList"
              :key="item.labelValue"
              v-model="noticeDetail.radioType"
              :label="item.labelValue"
              >{{ item.labelName }}</el-radio
            >
          </el-form-item>
          <el-form-item
            v-if="noticeDetail.radioType === 'XCX'"
            label="ID"
            prop="appletId"
          >
            <el-input disabled v-model="noticeDetail.appletId" clearable />
          </el-form-item>
          <el-form-item v-else label="跳转链接">
            <el-input v-model="noticeDetail.url" disabled></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="success" @click="dialogData.isShow = false"
            >确 定</el-button
          >
          <el-button @click="dialogData.isShow = false">关 闭</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getNoticeDetailAPI } from '@/api/noticeManagement/noticeManage'
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  props: ['dialogData'],
  data() {
    return {
      noticeId: '',
      noticeDetail: {},
      terminalTypeList: [], // 显示终端
      touchTypeList: [], //触达通道
      radioList: [
        { labelName: '详情链接', labelValue: 'URL' },
        { labelName: '小程序', labelValue: 'XCX' }
      ]
    }
  },
  mounted() {
    this.noticeId = this.dialogData.params
    this.getNoticeDetail()
    this.getStatusList()
  },
  methods: {
    async getStatusList() {
      // 显示终端
      let data = await sysNormalDisable('pop_screen_terminal')
      this.terminalTypeList = this.terminalTypeList.concat(data)
      const touchTypeList = await sysNormalDisable('activity_notice_type')
      this.touchTypeList = touchTypeList
    },
    getNoticeDetail() {
      getNoticeDetailAPI(
        this.noticeId,
        (response) => {
          let obj = { ...response }
          //radioType赋值
          obj.radioType = response.appletId ? 'XCX' : 'URL'
          this.noticeDetail = obj
          //字符串转数组
          this.noticeDetail.displayTerminals = response.displayTerminals[0]
        },
        (response) => {
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    }
  }
}
</script>
<style lang="less">
#dialogDetailData {
  .bomb-img {
    width: 178px;
    height: 178px;
  }
}
</style>
